package com.sample.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sample.action.form.AreaForm;
import com.sample.javabean.Area;
import com.sample.util.Pager;


/**
 * 
 * @author 演示
 * 
 */
public class AreaAction extends BaseAction {

	private final static Log log = LogFactory.getLog(AreaAction.class);
	private AreaForm areaForm = new AreaForm();
	private Integer id;
	private Pager<Area> pageList;
	private String keywords;
	
	// 使用new()操作符实例化领域模型
	private Area area = new Area();

	/**
	 * 添加
	 * 
	 * @return
	 * @throws Exception
	 */
	public String add()throws Exception{
		try{
			log.info("add Area:"+areaForm.getAgenname());
			if(areaForm!=null){
				area.setCityno(areaForm.getCityno());
				area.setHandleno(areaForm.getHandleno());
				area.setAgenName(areaForm.getAgenname());
				area.setType(areaForm.getType());
				area.addArea();	
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
	}

	/**
	 * 显示记录列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listArea() throws Exception {
		try {

			pageList = area.list(page, size, areaForm,keywords);
			return "listArea";
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}

	}

	public String inputArea() throws Exception {
		return "inputArea";
	}

	public String editArea() throws Exception {
		try {
			area.setId(id);
			area.load();
			return "editArea";
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public String edit() throws Exception {
		try {
			if (areaForm != null) {
				area.setId(areaForm.getId());
				area.setCityno(areaForm.getCityno());
				area.setHandleno(areaForm.getHandleno());
				area.setAgenName(areaForm.getAgenname());
				area.setType(areaForm.getType());

				area.editArea();
			}
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public String del() throws Exception {
		try {
			if (areaForm != null) {
				area.setId(id);
				area.delArea();
			}
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	public AreaForm getAreaForm() {
		return areaForm;
	}

	public void setAreaForm(AreaForm areaForm) {
		this.areaForm = areaForm;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Pager<Area> getPageList() {
		return pageList;
	}

	public void setPageList(Pager<Area> pageList) {
		this.pageList = pageList;
	}

	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}
	
}
